from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get('https://www.baidu.com/')
driver.maximize_window()

# 索引
case = driver.find_element(By.CSS_SELECTOR, 'form[id="form"] :nth-child(8)')
print(case.get_attribute('outerHTML'))  # 打印的是form标签下的第8个子标签

case = driver.find_element(By.CSS_SELECTOR, 'form[id="form"] :nth-of-type(8)')
print(case.get_attribute('outerHTML'))  # 打印的是form标签下的第8个input子标签

# 模糊匹配
case = driver.find_element(By.CSS_SELECTOR, 'input[name*="_idx"]')
print(case.get_attribute('outerHTML'))  # 打印name属性包含'_idx'的所有标签属性

# 多条件查找
case = driver.find_element(By.CSS_SELECTOR, 'input[name="wd"][autocomplete="off"]')
print(case.get_attribute('outerHTML'))  # 打印name是'wd'并且自动完成是'off'的所有标签属性

driver.quit()
